package com.vincce.sport.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.vincce.sport.entity.ScoreApi;
import com.vincce.sport.mapper.TeamDataTaskMapper;


@Controller
@RequestMapping("/teamScoreApi")
public class TeamScoreApiController extends BaseController{
	@Resource
	private TeamDataTaskMapper dataTaskMapper;
	
	/**
	 * 接口返回球队场均得分
	 * @param seasonId
	 * @param limit
	 * @return
	 */
	@RequestMapping("/queryScoreApi")
	@ResponseBody
	public String queryScoreApi(Integer seasonId,Integer limit,Integer offset, HttpServletRequest request){
		Map<String, Object> map =new HashMap<String, Object>();
		Map<String, Object> result =new HashMap<String, Object>();
		Boolean flag=checkIp(request);
		if (flag==true) {
			if (seasonId!=null) {
				map.put("seasonId", seasonId);
				if (limit!=null) {
					map.put("limit", limit);
				}
				else{
					map.put("limit", 10);
				}
				
				if (offset!=null) {
					map.put("offset", offset);
				}
				
				else{
					map.put("offset", 0);
				}
				
				List<ScoreApi> dataTasks = dataTaskMapper.queryTeamScoreApi(map);
				
				result.put("list", dataTasks);
				result.put("suc", true);
				result.put("msg", "成功");
			}
			else if(seasonId==null) {
				result.put("suc", false);
				result.put("msg", "调用接口失败，赛季ID不能为空");
			}
		}
		
		else{
			result.put("suc", false);
			result.put("msg", "调用接口失败，IP不合法");
		}
		return JSON.toJSONString(result);	
	}
}
